package com.jmu.medicineknows.controller;

import com.jmu.medicineknows.dto.DrugPageDto;
import com.jmu.medicineknows.entity.Result;
import com.jmu.medicineknows.entity.SaleRecord;
import com.jmu.medicineknows.entity.ShoppingCart;
import com.jmu.medicineknows.service.SalesStatisticsService;
import com.jmu.medicineknows.service.ShoppingCartService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: JieZi
 * @Date: 2023/7/14 09:14
 * @Description:
 **/
@RestController
@RequestMapping("/shopping")
public class ShoppingCartController {
    @Resource
    ShoppingCartService shoppingCartService;
    @RequestMapping(value = "/list")
    public Result getShoppingCart(@RequestBody DrugPageDto pageDto){
        return shoppingCartService.getList(pageDto);
    }
    @PostMapping("/cart")
    public Result addToCart(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.addToCart(shoppingCart);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody ShoppingCart shoppingCart){
        System.out.println(shoppingCart);
        return shoppingCartService.updateCart(shoppingCart);
    }
    @RequestMapping("/delete")
    public Result delete(@RequestBody List<Integer> ids){
        System.out.println(ids);
        return shoppingCartService.delete(ids);
    }
    @RequestMapping("/order")
    public Result order(@RequestBody List<ShoppingCart> shoppingCarts){
        System.out.println(shoppingCarts);
       Result result= shoppingCartService.order(shoppingCarts);
        System.out.println(result.toString()+"---------------");
        return result;
    }

}